var win = Titanium.UI.currentWindow;
var module="file_operation?";
var path="";
var offset=0;
var totalResult=30;
var showFolder=true;
var showFile=true;
var moreInfo=true;
var mimeT="";
var listFS=[];

win.title='FileSystem';
win.backgroundColor='#000';

var ht = Titanium.Network.createHTTPClient();

var table = Titanium.UI.createTableView();
var view = Titanium.UI.createView({borderRadius:10,width:300,top:60,bottom:110});
listFS.push(table);
view.add(table);
win.add(view);

	


table.addEventListener("click",function(e){
	if(e.row.isFolder=="yes"){
		var table = Titanium.UI.createTableView();
		var view = Titanium.UI.createView({borderRadius:10,width:300,top:60,bottom:110});
		getFolder(e.row.path);
		listFS.push(table);
		view.add(table);
		win.add(view);
	}else{
	}

})

ht.onload=function(){
	var doc = this.responseXML.documentElement;
	var files=doc.getElementsByTagName("file");
	var tData=[];
	
   	for(var i=0;i<files.length;i++){
//   		var file=files.item(0).getElementsByTagName("isFolder").item(0).text;
   		tData.push({
   			title:files.item(i).getElementsByTagName("name").item(0).text,
   			isFolder:files.item(i).getElementsByTagName("isFolder").item(0).text,
   			path:files.item(i).getElementsByTagName("path").item(0).text,
   			
   			})
   	}
	listFS[listFS.length-1].setData(tData);
}

ht.onerror=function(){
	alert("Can't connect to "+Titanium.App.ip);
}

function getFolder(tpath){
	var tpath = tpath.split("/opt/sybhttpd/localhost.drives/").join("");
//	alert("http://"+Titanium.App.ip+":8008/"+module+"arg0=list_user_storage_file&"+ "arg1=" + escape(tpath) + "&arg2=" + offset+ "&arg3=" + totalResult + "&arg4=" + showFolder + "&arg5=" + showFile + "&arg6=" + moreInfo + "&arg7=" + escape(mimeT));
	ht.open("GET","http://"+Titanium.App.ip+":8008/"+module+"arg0=list_user_storage_file&"+ "arg1=" + escape(tpath) + "&arg2=" + offset+ "&arg3=" + totalResult + "&arg4=" + showFolder + "&arg5=" + showFile + "&arg6=" + moreInfo + "&arg7=" + escape(mimeT),false);
	ht.send();
}




getFolder(path);